package day11;

import java.io.*;

public class homework02 {
    public static void main(String[] args) throws Exception {
        m1("d:\\1.mp3","d:\\copy.mp3",1);
        m1("d:\\1.mp3","d:\\copy.mp3",2);
        m1("d:\\1.mp3","d:\\copy.mp3",3);
        m1("d:\\1.mp3","d:\\copy.mp3",4);
    }
    public static void m1(String path1,String path2,int num) throws Exception{
        File f1=new File(path1);File f2=new File(path2);
        FileInputStream fis = new FileInputStream(f1);
        FileOutputStream fos = new FileOutputStream(f2);
        int a;
        if(num==1) {
            Long l1 = System.currentTimeMillis();
            while ((a = fis.read()) != -1) {
                fos.write(a);
            }
            Long l2=System.currentTimeMillis();
            System.out.println("消耗了"+(l2-l1)+"毫秒");
        }
        if(num==2) {
            int b;
            byte[] buf = new byte[1024];
            Long l1 = System.currentTimeMillis();
            while ((b = fis.read()) != -1) {
                fos.write(buf);
            }
            Long l2 = System.currentTimeMillis();
            System.out.println("消耗了" + (l2 - l1) + "毫秒");
        }
        FileReader fr=new FileReader(f1);FileWriter fw=new FileWriter(f2);
        BufferedReader br=new BufferedReader(fr);BufferedWriter bw=new BufferedWriter(fw);
        if(num==3) {
            int s;
            Long l1 = System.currentTimeMillis();
            while((s=br.read())!=-1){
                bw.write(s);
            }
            Long l2 = System.currentTimeMillis();
            System.out.println("消耗了" + (l2 - l1) + "毫秒");
        }
        if(num==4) {
            String s;
            Long l1 = System.currentTimeMillis();
            while((s=br.readLine())!=null){
                bw.write(s);
            }
            Long l2 = System.currentTimeMillis();
            System.out.println("消耗了" + (l2 - l1) + "毫秒");
        }
        fis.close();
        fos.close();
        bw.close();
        br.close();
    }
}
